<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<ss:Workbook xmlns:x="urn:schemas-microsoft-com:office:excel"
             xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<ss:Styles>
  <!-- Default -->
  <ss:Style ss:ID="Default" ss:Name="Normal">
    <ss:Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>
    <ss:Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
  </ss:Style>
  <!-- End - Default -->
  <!-- Title -->
  <ss:Style ss:ID="Title">
    <ss:Font ss:Size="20"/>
  </ss:Style>
  <!-- End - Title -->
  <!-- Header -->
  <ss:Style ss:ID="Header">
    <ss:Borders>
      <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2" ss:Color="#0070A8"/>
      <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2" ss:Color="#0070A8"/>
      <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" ss:Color="#0070A8"/>
      <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2" ss:Color="#0070A8"/>
    </ss:Borders>
    <ss:Font ss:FontName="Arial" x:Family="Swiss" ss:Size="8" ss:Color="#FFFFFF" ss:Bold="1"/>
    <ss:Interior ss:Color="#006699" ss:Pattern="Solid"/>
  </ss:Style>
  <!-- End - Header -->
  <!-- BorderLeftBottom -->
  <ss:Style ss:ID="BorderLeftBottom">
    <ss:Borders>
      <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2" ss:Color="#0070A8"/>
      <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2" ss:Color="#0070A8"/>
    </ss:Borders>
  </ss:Style>
  <!-- End - BorderLeftBottom -->
  <!-- BorderRight -->
  <ss:Style ss:ID="BorderRight">
    <ss:Borders>
      <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" ss:Color="#0070A8"/>
      <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
    </ss:Borders>
  </ss:Style>
  <!-- End - BorderRight -->
  <!-- BorderBottom -->
  <ss:Style ss:ID="BorderBottom">
    <ss:Borders>
      <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2" ss:Color="#0070A8"/>
    </ss:Borders>
  </ss:Style>
  <!-- End - BorderBottom -->
  <!-- BorderRightBottom -->
  <ss:Style ss:ID="BorderRightBottom">
    <ss:Borders>
      <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" ss:Color="#0070A8"/>
      <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2" ss:Color="#0070A8"/>
    </ss:Borders>
  </ss:Style>
  <!-- End - BorderRightBottom -->
  <!-- HasData -->
  <ss:Style ss:ID="HasData">
    <ss:Borders>
      <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
      <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#808080"/>
    </ss:Borders>
  </ss:Style>
  <!-- End - HasData -->
</ss:Styles>

<ss:Worksheet ss:Name="Thời khóa biểu">
  <ss:Table ss:ExpandedColumnCount="15" ss:ExpandedRowCount="93" x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="15">
    <ss:Column ss:Width="47.25"/>
    <!-- Title -->
    <ss:Row ss:AutoFitHeight="0" ss:Height="26.25">
      <ss:Cell ss:Index="1"></ss:Cell>
      <ss:Cell ss:Index="2" ss:MergeAcross="13" ss:StyleID="Title">
        <ss:Data ss:Type="String">THỜI KHÓA BIỂU PHÒNG MÁY</ss:Data>
      </ss:Cell>
    </ss:Row>
    <!-- End - Title -->
    <!-- Header -->
    <ss:Row ss:AutoFitHeight="0" ss:Height="15.75">
      <ss:Cell ss:Index="1"></ss:Cell>
      <ss:Cell ss:Index="2" ss:StyleID="Header">
        <ss:Data ss:Type="String">Thứ</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="3" ss:StyleID="Header">
        <ss:Data ss:Type="String">Ca</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="4" ss:StyleID="Header">
        <ss:Data ss:Type="String">Tiết</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="5" ss:StyleID="Header">
        <ss:Data ss:Type="String">A101</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="6" ss:StyleID="Header">
        <ss:Data ss:Type="String">A102</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="7" ss:StyleID="Header">
        <ss:Data ss:Type="String">A105</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="8" ss:StyleID="Header">
        <ss:Data ss:Type="String">A106</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="9" ss:StyleID="Header">
        <ss:Data ss:Type="String">A109</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="10" ss:StyleID="Header">
        <ss:Data ss:Type="String">A110</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="11" ss:StyleID="Header">
        <ss:Data ss:Type="String">A111</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="12" ss:StyleID="Header">
        <ss:Data ss:Type="String">A017</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="13" ss:StyleID="Header">
        <ss:Data ss:Type="String">A018</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="14" ss:StyleID="Header">
        <ss:Data ss:Type="String">A019</ss:Data>
      </ss:Cell>
      <ss:Cell ss:Index="15" ss:StyleID="Header">
        <ss:Data ss:Type="String">A020</ss:Data>
      </ss:Cell>
    </ss:Row>
    <!-- End - Header -->
    <% @rooms = [101, 102, 105, 106, 109, 110, 111, 17, 18, 19, 20] %>
    <% if params[:day_month_year] %>
        <% @day_month_year = Date.strptime(params[:day_month_year], "%d/%m/%Y") %>
        <% @day_of_week = localize(@day_month_year, :format => '%A').to_i %>
        <% @week_of_day = (@day_month_year - Date.new(2013, 1, 14)).to_i/7+1 %>
    <% else %>
        <% @day_month_year = nil %>
        <% @day_of_week = nil %>
        <% @week_of_day = nil %>
    <% end %>

    <% if params[:week] %>
        <% @week = params[:week] %>
    <% else %>
        <% @week = nil %>
    <% end %>

    <% (@day_month_year ? @day_of_week..@day_of_week : 2..8).each do |thu| %>
        <% @check = Array.new %>
        <% (1..13).each do |c| %>
            <% @check[c] = 1 %>
        <% end %>

        <!-- Data Row -->
        <% (1..13).each do |tiet| %>
            <ss:Row ss:AutoFitHeight="0" ss:Height="15.75">
              <ss:Cell ss:Index="1"></ss:Cell>
              <% if tiet == 1 then %>
                  <ss:Cell ss:Index="2" ss:MergeDown="12" ss:StyleID="BorderLeftBottom">
                    <ss:Data ss:Type="String"><%= thu.to_thu %></ss:Data>
                  </ss:Cell>
              <% end %>

              <% if tiet == 1 then %>
                  <ss:Cell ss:Index="3" ss:MergeDown="4" ss:StyleID="HasData">
                    <ss:Data ss:Type="Number"><%= tiet/5+1 %></ss:Data>
                  </ss:Cell>
              <% end %>

              <% if tiet == 6 then %>
                  <ss:Cell ss:Index="3" ss:MergeDown="4" ss:StyleID="HasData">
                    <ss:Data ss:Type="Number"><%= tiet/5+1 %></ss:Data>
                  </ss:Cell>
              <% end %>

              <% if tiet == 11 then %>
                  <ss:Cell ss:Index="3" ss:MergeDown="2" ss:StyleID="BorderBottom">
                    <ss:Data ss:Type="Number">3</ss:Data>
                  </ss:Cell>
              <% end %>

              <% if tiet==13 %>
                  <ss:Cell ss:Index="4" ss:StyleID="BorderBottom">
                    <ss:Data ss:Type="Number"><%= tiet %></ss:Data>
                  </ss:Cell>
              <% else %>
                  <ss:Cell ss:Index="4" ss:StyleID="HasData">
                    <ss:Data ss:Type="Number"><%= tiet %></ss:Data>
                  </ss:Cell>
              <% end %>
              <% @rooms.each_with_index do |room, i| %>
                  <% @tkb = ThoiKhoaBieu.where("Thu = ? AND TietBD = ? AND MaPhong = ?", thu, tiet, room).first %>

                  <% unless @tkb.nil? %>
                      <% @weeks = @tkb.TGIn %>
                      <% @weeks = @weeks.chars.to_a %>
                      <% if (@week && @weeks[@week.to_i-1].to_i != (@week.to_i % 10)) || (@day_month_year && @weeks[@week_of_day-1].to_i != (@week_of_day % 10)) %>
                          <% @tkb=nil %>
                      <% end %>
                  <% end %>
                  <% if @check[i+1] == 1 %>
                      <% unless @tkb.nil? %>
                          <ss:Cell ss:Index="<%= i + 5 %>" ss:MergeDown="<%= @tkb.SoTiet.to_i - 1 %>" ss:StyleID="<%= (tiet==13 || (tiet+@tkb.SoTiet-1)==13) ? "BorderBottom" : "HasData" %>">
                            <ss:Data ss:Type="String"><%= (@tkb.MaLop + " " + @tkb.TenMH.first_char + " " + @tkb.TenGV).html_safe %></ss:Data>
                          </ss:Cell>
                      <% else %>
                          <ss:Cell ss:Index="<%= i + 5 %>" ss:StyleID="<%= "HasData" if tiet!=13 && @rooms.count != i+1 %><%= "BorderRight" if tiet!=13 && @rooms.count == i+1 %><%= "BorderBottom" if tiet==13 && @rooms.count != i+1 %><%= "BorderRightBottom" if tiet==13 && @rooms.count == i+1%>">
                            <ss:Data ss:Type="String"></ss:Data>
                          </ss:Cell>
                      <% end %>
                      <% @check[i+1] = @tkb.SoTiet unless @tkb.nil? %>
                  <% else %>
                      <% @check[i+1] = @check[i+1] - 1 %>
                  <% end %>
              <% end %>
            </ss:Row>
        <% end %>
    <% end %>
    <!-- End - Data Row -->
  </ss:Table>
</ss:Worksheet>
</ss:Workbook>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         